# 19feb12kernigh
# (c) Software Lab. Alexander Burger

# System macros
(data)
: stdin        word   __sF        # (&__sF[0])
: stdout       word   "__sF+152"  # (&__sF[1])
: stderr       word   "__sF+304"  # (&__sF[2])

(code 'errno_A 0)
   call __errno  # Get address of 'errno'
   ld4 (A)  # Load value
   ret

(code 'errnoC 0)
   call __errno  # Get address of 'errno'
   xchg A C
   st4 (C)  # Store new value
   ret

(code 's_isdirS_F 0)  # S_ISDIR
   ld4 (S `(+ I ST_MODE))  # Get 'st_mode' from 'stat'
   and A `S_IFMT
   cmp A `S_IFDIR
   ret

(code 'wifstoppedS_F 0)  # WIFSTOPPED
   ld A (S I)  # Get status
   cmp B `(oct "0177")  # (((status) & 0xff) == 0177)
   ret

(code 'wifsignaledS_F 0)  # WIFSIGNALED
   ld A (S I)  # Get status
   and B `(oct "0177")  # (((status) & 0177) + 1) >> 1) > 0)
   inc B
   shr B 1
   ret

(code 'wtermsigS_A 0)  # WTERMSIG
   ld A (S I)  # Get status
   and B `(oct "0177")  # ((status) & 0177)
   zxt
   ret

# vi:et:ts=3:sw=3
